﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoBackupDatabase.DBConection;

namespace AutoBackupDatabase
{
    using System.Data;
    using System.Data.SqlClient;

    using AutoBackupDatabase.ENT;

    public class EXPORTDAL
    {
         private DbConnection conn;
         public EXPORTDAL()
        {
            conn = new DbConnection();
        }

         public int ISTABLEHAVEGUEST(int tableId)
         {
             string query = string.Format("exec ISTABLEHAVEGUEST " + tableId);
             DataTable ds = conn.executeGetQuery(query);
             return int.Parse(ds.Rows[0][0].ToString());
         }
         public bool UPDATEVATSERVICEDISCOUNT(EXPORTENT ent)
         {
             string query = "exec  UPDATEVATSERVICEDISCOUNT @EXPORTID,@VAT,@SERVICE,@DISCOUNT ";
             SqlParameter[] sqlParameters = new SqlParameter[4];
             sqlParameters[0] = new SqlParameter("@EXPORTID", SqlDbType.VarChar);
             sqlParameters[0].Value = ent.EXPORTID;
             sqlParameters[1] = new SqlParameter("@VAT", SqlDbType.Float);
             sqlParameters[1].Value = ent.VAT;
             sqlParameters[2] = new SqlParameter("@SERVICE", SqlDbType.Float);
             sqlParameters[2].Value = ent.SERVICE;
             sqlParameters[3] = new SqlParameter("@DISCOUNT", SqlDbType.Float);
             sqlParameters[3].Value = ent.TABLEDISCOUNT;
            
             return conn.executeUpdateQuery(query, sqlParameters);
         }

         public string GETNUMBEROFEXPORT(int tableId,int empId)
         {
             string query = string.Format("exec GETNUMBEROFEXPORT " + tableId + "," + empId);
             DataTable ds = conn.executeGetQuery(query);
             return ds.Rows[0][0].ToString();
         }

         public bool  ADDITEMTOTABLE(string exportID, int itemId,int quantity)
         {
             string query = string.Format("exec ADDITEMTOTABLE " + exportID + "," + itemId + "," + quantity);
             DataTable ds = conn.executeGetQuery(query);
             var result = ds.Rows[0][0].ToString();
             return bool.Parse(ds.Rows[0][0].ToString());
         }


         public bool PAIDBILL(string expId, DateTime datePaid)
         {
             string query = "exec  PAIDBILL @EXPORTID,@DATEPAID ";
             SqlParameter[] sqlParameters = new SqlParameter[2];
             sqlParameters[0] = new SqlParameter("@EXPORTID", SqlDbType.VarChar);
             sqlParameters[0].Value = expId;
             sqlParameters[1] = new SqlParameter("@DATEPAID", SqlDbType.DateTime);
             sqlParameters[1].Value = datePaid;
            

             return conn.executeUpdateQuery(query, sqlParameters);
         }

         public EXPORTENT GETEXPORTBYEXPORTID(string ExportID)
         {
             string query = string.Format("exec GETEXPORTBYEXPORTID @EXPORTID");

             SqlParameter[] sqlParameters = new SqlParameter[1];
             sqlParameters[0] = new SqlParameter("@EXPORTID", SqlDbType.VarChar);
             sqlParameters[0].Value = ExportID;

             DataTable ds = conn.executeSelectQuery(query, sqlParameters);

             EXPORTENT ent = new EXPORTENT();
             foreach (DataRow item in ds.Rows)
             {
                 ent.DATECREATE =DateTime.Parse( item["DATECREATE"].ToString());
                 ent.EMPLOYERID = item["EMPLOYERID"].ToString();
                 ent.EMPLOYERNAME = item["FULLNAME"].ToString();
                 ent.EXPORTID = item["EXPORTID"].ToString();
                 ent.SERVICE =float.Parse(item["SERVICE"].ToString());
                 ent.TABLEDISCOUNT =double.Parse(item["TABLEDISCOUNT"].ToString());
                 ent.TABLEID = int.Parse(item["TABLEID"].ToString());
                 ent.TABLENAME = item["TABLENAME"].ToString();
                 ent.VAT =float.Parse( item["VAT"].ToString());
                 ent.AREANAME = item["AREANAME"].ToString();


             }

             return ent;
         }
    }
}
